
function ListNode(val, next) {
    this.val = (val === undefined ? 0 : val);
    this.next = (next === undefined ? null : next);
}
l1 = [2,4,3], l2 = [5,6,4]
var addTwoNumbers = function(l1, l2) {
     let head= new ListNode()
     let cur=head
     let carry = 0
     while(l1 !== null || l2 !== null || carry !== 0)
     {
       
          const val1=l1?l1.val:0
          const val2=l2?l2.val:0
          const sum=val1+val2+carry
          carry=Math.floor(sum/10)
          const digit=sum%10
          cur.next=new ListNode(digit)
          cur=cur.next         
       
       if(l1)l1=l1.next
       if(l2)l2=l2.next
     }
     return head.next
};
console.log(addTwoNumbers(l1,l2))